package com.sz.web.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {

    public static boolean isBlank(Object str) {
        return (str == null || "".equals(str) || "".equals(String.valueOf(str).trim()));
    }

    public static boolean isNotBlank(Object str) {
        boolean result = isBlank(str);
        return !result;
    }

    /**
     * 子字符串modelStr在字符串str中第count次出现时的下标
     *
     * @param str      字符串
     * @param modelStr 字符
     * @param count    第几次
     * @return  下标
     */
    public static Integer getFromIndex(String str, String modelStr, Integer count) {
        String[] strArr = str.split(modelStr);
        Integer index = -1;
        Integer eachCount = 0;
        if (strArr.length < count){
            return -1;
        }
        if (str.startsWith(modelStr) && !str.endsWith(modelStr) && strArr.length <= count){
            return -1;
        }
        for (int i = 0; i < strArr.length; i++) {
            if (eachCount.equals(count)){
                break;
            }
            eachCount++;
            if (i == 0) {
                if (str.startsWith(modelStr)){
                    index = index + modelStr.length();
                    continue;
                }
            }
            index = index + strArr[i].length() + modelStr.length();
        }
        return index;
    }
}
